package bTree.LeetCode;

import javax.swing.tree.TreeNode;

public class 判断平衡二叉树 {
    public boolean isBalanced(TreeNode root) {
        if(root==null){
            return true;
        }
       if(Math.abs(maxDepth(root.left)-maxDepth(root.right))>1 ){
           return false;
       }
       return isBalanced(root.left)&&isBalanced(root.right);
    }

    int maxDepth(TreeNode node){
        if(node==null){
            return 0;
        }
        return Math.max(maxDepth(node.left),maxDepth(node.right))+1;
    }
}